package com.springcloud.zuul.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;

/**
 * @program: springcloud-zuul
 * @description:
 * @author: zhlu
 * @create: 2019-12-26 18:26
 * @Introduction(说明背景故事)
 **/
public class RedissonConfig {

    @Value("${spring.redis.host}")
    private String host;

    @Value("${spring.redis.port}")
    private String port;

    @Value("${spring.redis.database}")
    private int database;

    @Value("${spring.redis.timeout}")
    private int timeout;

    @Value("${spring.redis.jedis.pool.max-active}")
    private int active;

//    @Value("${spring.redis.password}")
//    private String password;

    @Bean
    public RedissonClient redisson() {
        Config config = new Config();
        config.setCodec(new org.redisson.client.codec.StringCodec());
        config.useSingleServer()
                .setAddress(String.format("redis://%s:%s", host, port))
                .setDatabase(database)
                .setConnectionPoolSize(active)
                .setIdleConnectionTimeout(timeout)
                .setConnectTimeout(timeout);
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }
}
